package com.theydream.qeechain.main;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;

import com.theydream.qeechain.R;
import com.theydream.qeechain.collection.GalleryFlow;
import com.theydream.qeechain.collection.ImageAdapter;
import com.theydream.qeechain.collection.PetInfo;
import com.theydream.qeechain.globaldata.CaughtItemListClass;
import com.theydream.qeechain.globaldata.GlobalData;
import com.theydream.qeechain.globaldata.definition.CaughtPet;

public class Collected extends Activity {
	private static CaughtItemListClass caughtItemListClass=CaughtItemListClass.getInstance();
	
	
	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.gallery_flow);

        GlobalData.getInstance().getDbhelper().loadPetInfo();
        GlobalData.getInstance().getDbhelper().loadCaughtPets();
        
//        List<Integer> imageList = new ArrayList<Integer>();
//        for (CaughtPet pet : caughtItemListClass.getItemList())	{
//        	imageList.add(this.getResources().getIdentifier(pet.getPet().getPic(), "drawable", this.getPackageName()));
//        }

        Integer [] image = new Integer [caughtItemListClass.getItemList().size()];
        int i = 0;
        for (CaughtPet pet : caughtItemListClass.getItemList())	{
        	image[i++] = this.getResources().getIdentifier(pet.getPet().getPic(), "drawable", this.getPackageName());
        }
        
        ImageAdapter adapter = new ImageAdapter(this, image);
        adapter.createReflectedImages();
        GalleryFlow galleryFlow = (GalleryFlow) findViewById(R.id.GalleryFlow);
        galleryFlow.setAdapter(adapter);
        galleryFlow.setClickable(true);
        galleryFlow.setOnItemClickListener(new OnItemClickListener()	{
			@Override
			public void onItemClick(AdapterView<?> parent, View view, int position,
					long id) {
        		Intent intent=new Intent(Collected.this, PetInfo.class);
        		Bundle bundle = new Bundle();
        		bundle.putInt("id", position);
        		intent.putExtras(bundle);
        		startActivity(intent);
			}
        });
	}
	
	public void goBack(View target) {
		this.finish();
	}
}

